﻿/*----------------------------------------------------------------
//  <copyright file="UserNameProvider.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2022-11-15 11:19</last-date>
//----------------------------------------------------------------*/

using Microsoft.AspNetCore.SignalR;

namespace MicroCloud.AspNetCore.SignalR
{
    #region "基于用户名的用户标识提供者"
    /// <summary>
    /// 基于用户名的用户标识提供者
    /// </summary>
    public class UserNameProvider : IUserIdProvider
    {
        #region "方法"
        #region "获取指定连接的用户ID"
        /// <summary>
        /// 获取指定连接的用户ID
        /// Gets the user ID for the specified connection
        /// </summary>
        /// <param name="connection">
        /// 获取用户ID的连接
        /// The connection to get the user ID for
        /// </param>
        /// <returns>
        /// 指定连接的用户ID
        /// The user ID for the specified connection
        /// </returns>
        public string GetUserId(HubConnectionContext connection)
        {
            return connection.User?.FindFirst(ClaimTypes.Name)?.Value;
        }
        #endregion

        #endregion

    }
    #endregion

}
